package com.travel.rabbit.entity;

import com.travel.rabbit.enums.BusinessEnum;
import lombok.Data;

/**
 * @author 云澜
 * @date 2021/12/22 2:39 下午
 */
@Data
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result() {}

    public static <T> Result<T> success(Integer code,String message) {
        Result<T> response = new Result();
        response.setCode(code);
        response.setMessage(message);
        response.setData(null);
        return response;
    }

    public static <T> Result<T> success(T data) {
        Result<T> response = new Result();
        response.setCode(BusinessEnum.SUCCESS.getCode());
        response.setMessage(BusinessEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }
    public static <T> Result<T> success() {
        Result<T> response = new Result();
        response.setCode(BusinessEnum.SUCCESS.getCode());
        response.setMessage(BusinessEnum.SUCCESS.getMsg());
        response.setData(null);
        return response;
    }
    public static <T> Result<T> error(T data) {
        Result<T> response = new Result();
        response.setCode(BusinessEnum.ERROR.getCode());
        response.setMessage(BusinessEnum.ERROR.getMsg());
        response.setData(data);
        return response;
    }

    public static <T> Result<T> error() {
        Result<T> response = new Result();
        response.setCode(BusinessEnum.ERROR.getCode());
        response.setMessage(BusinessEnum.ERROR.getMsg());
        response.setData(null);
        return response;
    }

    public static <T> Result<T> error(Integer code,String message) {
        Result<T> response = new Result();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}
